//
//  VC_RegistWriteCode.m
//  yjw-winner
//
//  Created by 隆霁 on 2018/9/20.
//  Copyright © 2018年 Shanghai decade financial information service co., LTD. All rights reserved.
//

#import "VC_RegistWriteCode.h"
#import "VC_RegistSetPassword.h"

@interface VC_RegistWriteCode ()
@property (weak, nonatomic) IBOutlet UIImageView *headImageView;
@property (weak, nonatomic) IBOutlet UIButton *nextStepButton;
@property (weak, nonatomic) IBOutlet UIButton *backButton;
@property (weak, nonatomic) IBOutlet UIButton *sendAginButton;
@property (weak, nonatomic) IBOutlet UITextField *codeNumberTextField;
@property (weak, nonatomic) IBOutlet UILabel *phoneNumberLabel;

@end

@implementation VC_RegistWriteCode
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    NSInteger index = [CountDownManager manager].currentCount;
    if (index == 60) {
        [self.sendAginButton setTitle:@"发送验证码" forState:UIControlStateNormal];
    }else {
        [self countDown];
    }
}

- (void)countDown {
    __weak typeof(self) weakself = self;
    [[CountDownManager manager] startWithCountDownManagerBlock:^(NSInteger number) {
        if (number > 0 && number < 60) {
            [weakself.sendAginButton setTitle:[NSString stringWithFormat:@"%ld", number] forState:UIControlStateNormal];
        }else {
            [weakself.sendAginButton setTitle:@"发送验证码" forState:UIControlStateNormal];
        }
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.headImageView.layer.masksToBounds = YES;
    self.headImageView.layer.cornerRadius = self.headImageView.mj_w * 0.5;
    
    self.nextStepButton.layer.masksToBounds = YES;
    self.nextStepButton.layer.cornerRadius = 4.0f;
    
    self.backButton.layer.masksToBounds = YES;
    self.backButton.layer.cornerRadius = 4.0f;
    self.backButton.layer.borderColor = [UIColor grayColor].CGColor;
    self.backButton.layer.borderWidth = 1.0f;
    
    NSString *t = [NSString stringWithFormat:@"+86 %@", self.phoneNmber];
    NSString *lt = [NSString stringWithFormat:@"我们已经发送一条验证短信至%@", t];
    NSMutableAttributedString *mText = [[NSMutableAttributedString alloc] initWithString:lt];
    [mText addAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} range:[lt rangeOfString:t]];
    self.phoneNumberLabel.attributedText = mText;
    
}


#pragma mark --mark EVENT

- (IBAction)sendSMSButtonClick:(UIButton *)sender {
    if ([CountDownManager manager].currentCount == 60) {
        // 获取短信
        // 倒计时
        [self countDown];
    }else {
        
    }
}
- (IBAction)nextStepButtonClick:(UIButton *)sender {
    // 验证验证码
    // 跳转界面
    VC_RegistSetPassword *vc = [[UIStoryboard storyboardWithName:@"LoginStoryBoard" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:NSStringFromClass([VC_RegistSetPassword class])];
    vc.phoneNumber = self.phoneNmber;
    [self.navigationController pushViewController:vc animated:YES];
}




@end
